package com.ssy.system.controller;

import com.ssy.common.Constant;
import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import com.ssy.system.pojo.Inspect;
import com.ssy.system.service.ICommonTypeService;
import com.ssy.system.service.IInspectService;
import com.ssy.system.vo.InspectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 检查费用
 *
 * @author ssy
 */
@RestController
@RequestMapping("/inspect")
public class InspectController {

    @Autowired
    private IInspectService inspectService;

    @Autowired
    private ICommonTypeService commonTypeService;

    /**
     * 检查费用的分页查询
     *
     * @param inspectVo
     * @return
     */
    @GetMapping("/loadAllInspectPage")
    public PageResult loadAllInspectPage(InspectVo inspectVo) {
        return this.inspectService.loadAllInspectPage(inspectVo);
    }

    /**
     * 添加检查费用
     *
     * @param inspect
     * @return
     */
    @PostMapping("/addInspect")
    public Result addInspect(@RequestBody Inspect inspect) {
        inspect.setCreateTime(new Date());
        return this.inspectService.insertInspect(inspect);
    }

    /**
     * 修改检查费用
     *
     * @param inspect
     * @return
     */
    @PostMapping("/updateInspect")
    public Result updateInspect(@RequestBody Inspect inspect) {
        return this.inspectService.updateInspect(inspect);
    }

    /**
     * 删除检查费用
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteInspect/{id}")
    public Result deleteInspect(@PathVariable Integer id) {
        return this.inspectService.deleteInspectById(id);
    }

    /**
     * 批量删除检查费用
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/bathDeleteInspect/{ids}")
    public Result bathDeleteInspect(@PathVariable Integer[] ids) {
        return this.inspectService.bathDeleteInspect(ids);
    }

    /**
     * 修改检查费用状态
     *
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updateInspectState/{id}/{state}")
    public Result updateInspectState(@PathVariable Integer id, @PathVariable Integer state) {
        Inspect inspect = new Inspect();
        inspect.setId(id);
        inspect.setState(state);
        return this.inspectService.updateInspect(inspect);
    }

    /**
     * 加载所有的项目类型
     *
     * @return
     */
    @GetMapping("/loadAllInspectType")
    public Result loadAllInspectType() {
        return this.commonTypeService.queryAllCommonType(Constant.INSPECT_TYPE);
    }


}
